import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import type {
  LoadingConfig,
  AdaptiveConfig,
  PaginationProps
} from "@pureadmin/table";
import { delay } from "@pureadmin/utils";
import { addDialog } from "@/components/ReDialog";
// import editForm from "./form.vue";
import { message } from "@/utils/message";
import dayjs from "dayjs";
// import { usePublicHooks } from "@/views/system/hooks";
interface FormItemProps {
  id?: string;
  region?: string;
  type?: string;
  area?: string;
  time?: string;
  violation?: string;
  description?: string;
  status?: string;
  date?: string;
  officer?: string;
}

export function useDept() {
  const title = "违规行驶线路报警";

  const formModel = ref<FormItemProps>({
    status: "0"
  });

  const date = dayjs(new Date()).format("YYYY-MM-DD");
  const columns: TableColumnList = [
    { label: "报警编号", prop: "报警编号" },
    { label: "车辆编号", prop: "车辆编号" },
    { label: "车牌号", prop: "车牌号" },
    { label: "司机姓名", prop: "司机姓名" },
    { label: "报警类型", prop: "报警类型" },
    { label: "报警时间", prop: "报警时间" },
    { label: "违规地点", prop: "违规地点" },
    { label: "违规情况描述", prop: "违规情况描述" },
    { label: "指定路线", prop: "指定路线" },
    { label: "偏离原因", prop: "偏离原因" },
    { label: "处理状态", prop: "处理状态" },
    { label: "处理时间", prop: "处理时间" },
    { label: "处理人员", prop: "处理人员" },
    {
      label: "操作",
      prop: "操作",
      slot: "operation"
    }
  ];
  const addIcon = useRenderIcon(AddFill);
  const editIcon = useRenderIcon(EditPen);
  const delIcon = useRenderIcon(Delete);
  // // const { tagDisableStyle } = usePublicHooks();
  const rules: any[] = [
    {
      报警编号: "R001",
      车辆编号: "V12345",
      车牌号: "鄂A12345",
      司机姓名: "张三",
      报警类型: "线路偏离",
      报警时间: "2024/10/1 7:30",
      违规地点: "武汉市黄陂区前川街道",
      违规情况描述: "偏离指定运输路线",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "道路施工改道",
      处理状态: "已处理",
      处理时间: "2024/10/1 8:00",
      处理人员: "王五"
    },
    {
      报警编号: "R002",
      车辆编号: "V54321",
      车牌号: "鄂B54321",
      司机姓名: "李四",
      报警类型: "线路偏离",
      报警时间: "2024/10/1 11:15",
      违规地点: "武汉市黄陂区武湖路段",
      违规情况描述: "偏离路线进入禁行区",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "避开拥堵",
      处理状态: "已处理",
      处理时间: "2024/10/1 11:45",
      处理人员: "赵六"
    },
    {
      报警编号: "R003",
      车辆编号: "V67890",
      车牌号: "鄂C67890",
      司机姓名: "王五",
      报警类型: "线路偏离",
      报警时间: "2024/10/2 15:00",
      违规地点: "武汉市黄陂区罗汉寺街道城乡结合部",
      违规情况描述: "未按指定路线行驶",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "司机未按导航指引行驶",
      处理状态: "处理中",
      处理时间: "2024/10/2 15:30",
      处理人员: "李四"
    },
    {
      报警编号: "R004",
      车辆编号: "V11223",
      车牌号: "鄂D11223",
      司机姓名: "赵六",
      报警类型: "线路偏离",
      报警时间: "2024/10/3 9:45",
      违规地点: "武汉市黄陂区六指街道路段",
      违规情况描述: "偏离指定路线超出1公里",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "避开限高设施",
      处理状态: "未处理",
      处理时间: "",
      处理人员: ""
    },
    {
      报警编号: "R005",
      车辆编号: "V33445",
      车牌号: "鄂E33445",
      司机姓名: "陈七",
      报警类型: "线路偏离",
      报警时间: "2024/10/3 18:20",
      违规地点: "武汉市黄陂区武湖街道沿江区域",
      违规情况描述: "偏离路线进入敏感区域",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "夜间道路封闭",
      处理状态: "已处理",
      处理时间: "2024/10/3 18:45",
      处理人员: "张三"
    },
    {
      报警编号: "R006",
      车辆编号: "V99887",
      车牌号: "鄂F99887",
      司机姓名: "周八",
      报警类型: "线路偏离",
      报警时间: "2024/10/4 10:05",
      违规地点: "武汉市黄陂区木兰山风景区",
      违规情况描述: "超出指定路线2公里",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "未按规定路线返回",
      处理状态: "未处理",
      处理时间: "",
      处理人员: ""
    },
    {
      报警编号: "R007",
      车辆编号: "V77654",
      车牌号: "鄂G77654",
      司机姓名: "吴九",
      报警类型: "线路偏离",
      报警时间: "2024/10/5 16:30",
      违规地点: "武汉市黄陂区滠口街道",
      违规情况描述: "车辆偏离指定路线，进入禁行区",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "道路堵塞绕行",
      处理状态: "已处理",
      处理时间: "2024/10/5 18:00",
      处理人员: "王五"
    },
    {
      报警编号: "R008",
      车辆编号: "V80901",
      车牌号: "鄂H80901",
      司机姓名: "郑十",
      报警类型: "非法时间行驶",
      报警时间: "2024/10/6 5:45",
      违规地点: "武汉市黄陂区罗汉寺街道城乡结合部",
      违规情况描述: "偏离路线超出500米",
      指定路线: "黄陂区-黄陂区指定线路",
      偏离原因: "司机疏忽",
      处理状态: "处理中",
      处理时间: "2024/10/6 9:00",
      处理人员: "赵六"
    }
  ];
  const formRef = ref();
  const dataList = ref([]);
  const loading = ref(true);
  /** 分页配置 */
  const pagination = reactive<PaginationProps>({
    pageSize: 20,
    currentPage: 1,
    pageSizes: [20, 40, 60],
    total: 0,
    align: "right",
    background: true,
    size: "default"
  });

  /** 加载动画配置 */
  const loadingConfig = reactive<LoadingConfig>({
    text: "正在加载第一页...",
    viewBox: "-10, -10, 50, 50",
    spinner: `
        <path class="path" d="
          M 30 15
          L 28 17
          M 25.61 25.61
          A 15 15, 0, 0, 1, 15 30
          A 15 15, 0, 1, 1, 27.99 7.5
          L 15 15
        " style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
      `
    // svg: "",
    // background: rgba()
  });

  /** 撑满内容区自适应高度相关配置 */
  const adaptiveConfig: AdaptiveConfig = {
    /** 表格距离页面底部的偏移量，默认值为 `96` */
    offsetBottom: 110
    /** 是否固定表头，默认值为 `true`（如果不想固定表头，fixHeader设置为false并且表格要设置table-layout="auto"） */
    // fixHeader: true
    /** 页面 `resize` 时的防抖时间，默认值为 `60` ms */
    // timeout: 60
    /** 表头的 `z-index`，默认值为 `100` */
    // zIndex: 100
  };

  function onSizeChange(val) {
    console.log("onSizeChange", val);
  }

  function onCurrentChange(val) {
    loadingConfig.text = `正在加载第${val}页...`;
    loading.value = true;
    delay(600).then(() => {
      loading.value = false;
    });
  }

  async function onSearch(newItem?: any) {
    loading.value = true;
    dataList.value = newItem ? [newItem].concat(rules) : rules;
    pagination.total = dataList.value.length;
    setTimeout(() => {
      loading.value = false;
    }, 500);
  }

  const resetForm = formEl => {
    if (!formEl) return;
    formEl.resetFields();
    onSearch();
  };
  function handleDelete(row: any) {
    console.log(row, "row");

    message(`操作成功`, { type: "success" });
    onSearch();
  }

  onMounted(() => {
    onSearch();
  });
  return {
    title,
    formModel,
    columns,
    addIcon,
    editIcon,
    delIcon,
    resetForm,
    onSearch,
    loading,
    dataList,
    pagination,
    loadingConfig,
    adaptiveConfig,
    onSizeChange,
    onCurrentChange,
    handleDelete
  };
}
